lines = ['#'*20," "," "," "," ",'#'*20,]
backlight_is_on = False

import os

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

#def callback_method(a,b):
    #print "orginial function"

funcdict = {
    #'callback' : callback_method
}

def clear():
    os.system('cls' if os.name == 'nt' else 'clear')

def display(line, string):
    lines[line] = string
    clear()
    for line in lines:
        print line

def refresh():
    clear()
    for line in lines:
        print line
        
def key(event):
    """shows key or tk code for the key"""
    if event.keysym == 'Escape':
        root.destroy()
    funcdict[0](event.keysym, event.char)
    #print 'key: ',event.keysym,', char: ',event.char 

def wait_for_keypress(callback):
    funcdict[0] = callback
    global root
    root = tk.Tk()
    root.bind_all('<Key>', key)
    # don't show the tk window
    #root.withdraw()
    root.mainloop()

def is_backlight_on():
    return backlight_is_on
    
def backlight_on():
    global backlight_is_on
    backlight_is_on = True
    refresh()
    #print 'backlight on'
    
def backlight_off():
    global backlight_is_on
    backlight_is_on = False
    clear()
    #print 'backlight off'
    
